# Contributor: Carlo Landmeter <clandmeter@gmail.com>
# Maintainer: 7heo <7heo@mail.com>
pkgname=gogs
pkgver=0.11.91
pkgrel=2
pkgdesc="A painless self-hosted Git service"
url="https://gogs.io/"
# buildmode=pie not available on mips64
arch="all !mips !mips64"
license="MIT"
depends="git"
makedepends="go perl libcap"
install="$pkgname.pre-install"
pkgusers="gogs"
pkggroups="www-data"
options="!check" # go race fails
subpackages="${pkgname}-openrc"
source="${pkgname}-${pkgver}.tar.gz::https://github.com/gogs/$pkgname/archive/v$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd
	$pkgname.ini"
builddir="$srcdir/github.com/gogs/$pkgname"

prepare() {
	mkdir -p "$srcdir"/github.com/gogs
	mv "$srcdir"/$pkgname-$pkgver "$builddir"/ || return 1
	default_prepare
}
build() {
	export GOPATH="$startdir"
	cd "$builddir" || return 1
	go fix || return 1
	# Note: sqlite causes problems without the pie buildmode
	go build -buildmode=pie -v -tags "sqlite redis memcache cert" ||return 1
}
package() {
	cd "$builddir"

	install -d -m 0755 \
		"$pkgdir"/usr/share/webapps/$pkgname || return 1

	# TODO: Is it really necessary to be world-readable?!
	install -d -m 0755 -o gogs -g www-data \
		"$pkgdir"/var/lib/$pkgname \
		"$pkgdir"/var/lib/$pkgname/git \
		"$pkgdir"/var/lib/$pkgname/db \
		"$pkgdir"/var/lib/$pkgname/avatars \
		"$pkgdir"/var/lib/$pkgname/attachements \
		"$pkgdir"/var/cache/$pkgname/sessions \
		"$pkgdir"/var/log/$pkgname \
		"$pkgdir"/etc/$pkgname/conf || return 1

	install -D -m 0755 $pkgname \
		"$pkgdir"/usr/bin/$pkgname || return 1
	# Allow to bind to port 80.
	setcap cap_net_bind_service=+ep \
		"$pkgdir"/usr/bin/$pkgname || return 1

	install -D -m 0664 -o gogs -g www-data "$srcdir"/${pkgname}.ini \
		"$pkgdir"/etc/$pkgname/conf/app.ini || return 1

	mv public templates "$pkgdir"/usr/share/webapps/$pkgname/ || return 1

	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="9c92d198f48e879a783f0e2e066db946a67a52d6ce3429a9ffeb531c53657b0dd81962e3e1e7fac0871eb9689c94538c9678d6cf56360b670ea020951c995dbb  gogs-0.11.91.tar.gz
be5a9ef2cae1ee2e8106feb6a997ae06519af91fe57f746d20996e79c332c93bb43fc53f79ff4e8ce13222afc6f3dc7bc5cbb758ef201b03e49d809c87c8c4c7  gogs.initd
52ce41c05c263b790221a04d13d2eb9bba689e4bd72daf5b6af31416e80a485a46bae19e18581d7bde879307283847e6486686a2fe4140fe38ebb6f315e11a86  gogs.confd
1d8cc4d9c96887de50d281f49d7f0bae963318a56a9e6cc46052d72236e446d20eb6228b8f51e24d5dbe63bf459040fb3556e9554fa242f3bef3969e11d18b06  gogs.ini"
